package com.lcl.jarvis.dto;

import com.lcl.jarvis.entity.DoctorsDO;
import org.springframework.beans.BeanUtils;
import com.lcl.jarvis.dto.DoctorsDTO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 转换
 */
public class DoctorsDtoAssembler {

    private DoctorsDtoAssembler() {
        // hide for utils
    }

    /**
     * 转换为DTO对象
     *
     * @param value
     * @return
     */
    public static DoctorsDTO toDoctorsDto(DoctorsDO value) {
        if (value == null) {
            return null;
        }
        DoctorsDTO dto = new DoctorsDTO();
        BeanUtils.copyProperties(value, dto);
        return dto;
    }

    /**
     * 转换为实体对象
     *
     * @param dto
     * @return
     */
    public static DoctorsDO toDoctorsDo(DoctorsDTO dto) {
        if (dto == null) {
            return null;
        }
        DoctorsDO value = new DoctorsDO();
        BeanUtils.copyProperties(dto, value);
        return value;
    }

    /**
     * 转换为DTO对象list
     *
     * @param doctorss
     * @return
     */
    public static List<DoctorsDTO> toDoctorsDtoList(List<DoctorsDO> doctorss) {
        if (doctorss == null) {
            return null;
        }
        return doctorss.stream().map(DoctorsDtoAssembler::toDoctorsDto).collect(Collectors.toList());
    }

    /**
     * 转换为实体对象list
     *
     * @param dtos
     * @return
     */
    public static List<DoctorsDO> toDoctorsDoList(List<DoctorsDTO> dtos) {
        if (dtos == null) {
            return null;
        }
        return dtos.stream().map(DoctorsDtoAssembler::toDoctorsDo).collect(Collectors.toList());
    }

}
